package net.lab1024.sa.admin.module.business.erp.mmo.service;

import java.util.List;

import net.lab1024.sa.admin.module.business.erp.inv.dao.InventordDao;
import net.lab1024.sa.admin.module.business.erp.mmo.dao.MrnordaDao;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.entity.MrnordaEntity;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.form.MrnordaAddForm;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.form.MrnordaQueryForm;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.form.MrnordaUpdateForm;
import net.lab1024.sa.admin.module.business.erp.mmo.domain.vo.MrnordaVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 领料通知单行 Service
 *
 * @Author AKITA
 * @Date 2025-08-17 17:01:32
 * @Copyright AKITA
 */

@Service
public class MrnordaService {

    @Resource
    private MrnordaDao mrnordaDao;
    @Resource
    private InventordDao inventordDao;


    public PageResult<MrnordaVO> queryPage(MrnordaQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<MrnordaVO> list = mrnordaDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }


    @Transactional
    public ResponseDTO<String> add(MrnordaAddForm addForm) {

        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(MrnordaUpdateForm updateForm) {
        MrnordaEntity mrnordaEntity = SmartBeanUtil.copy(updateForm, MrnordaEntity.class);
        mrnordaDao.updateById(mrnordaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        mrnordaDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        mrnordaDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
